home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_functions.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  10.8 KB  |  294 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. struct MUIP_FunctionsWin_ShowFunctionsMessage {
  31.     ULONG MethodID;
  32.     ULONG nodeType;
  33.     APTR base;
  34.     UBYTE *name;
  35. };
  36.  
  37. struct FunctionsEntry {
  38.     UBYTE fe_Address[16];
  39.     ULONG fe_Offset;
  40.     UBYTE fe_OffsetDec[16];
  41.     UBYTE fe_OffsetHex[16];
  42.     UBYTE fe_FuncName[64];
  43. };
  44.  
  45. static __asm __saveds LONG funclist_con2func(register __a2 Object *obj, register __a1 struct NList_ConstructMessage *msg, register __a0 struct Hook *hook)
  46. {
  47.     return AllocListEntry(msg->pool, msg->entry, sizeof(struct FunctionsEntry));
  48. }
  49.  
  50. MakeHook(funclist_con2hook, funclist_con2func);
  51.  
  52. static __asm __saveds LONG funclist_des2func(register __a2 Object *obj, register __a1 struct NList_DestructMessage *msg, register __a0 struct Hook *hook)
  53. {
  54.     FreeListEntry(msg->pool, &msg->entry);
  55.  
  56.     return 0;
  57. }
  58.  
  59. MakeHook(funclist_des2hook, funclist_des2func);
  60.  
  61. static __asm __saveds LONG funclist_dsp2func(register __a2 Object *obj, register __a1 struct NList_DisplayMessage *msg, register __a0 struct Hook *hook)
  62. {
  63.     struct FunctionsEntry *fe = (struct FunctionsEntry *)msg->entry;
  64.  
  65.     if (fe) {
  66.         msg->strings[0] = fe->fe_OffsetDec;
  67.         msg->strings[1] = fe->fe_OffsetHex;
  68.         msg->strings[2] = fe->fe_Address;
  69.         msg->strings[3] = fe->fe_FuncName;
  70.     } else {
  71.         msg->strings[0] = "Offset";
  72.         msg->strings[1] = "Hex";
  73.         msg->strings[2] = "Address";
  74.         msg->strings[3] = "Name";
  75.         msg->preparses[0] = MUIX_B;
  76.         msg->preparses[1] = MUIX_B;
  77.         msg->preparses[2] = MUIX_B;
  78.         msg->preparses[3] = MUIX_B;
  79.     }
  80.  
  81.     return 0;
  82. }
  83.  
  84. MakeHook(funclist_dsp2hook, funclist_dsp2func);
  85.  
  86. static LONG funclist_cmp2colfunc( struct FunctionsEntry *fe1,
  87.                                   struct FunctionsEntry *fe2,
  88.                                   ULONG column )
  89. {
  90.     switch (column) {
  91.         case 0:
  92.         case 1: return (LONG)fe1->fe_Offset - (LONG)fe2->fe_Offset;
  93.         case 2: return stricmp(fe1->fe_Address, fe2->fe_Address);
  94.         case 3: return stricmp(fe1->fe_FuncName, fe2->fe_FuncName);
  95.     }
  96. }
  97.  
  98. static __asm __saveds LONG funclist_cmp2func(register __a2 Object *obj, register __a1 struct NList_CompareMessage *msg, register __a0 struct Hook *hook)
  99. {
  100.     LONG cmp;
  101.     struct FunctionsEntry *fe1, *fe2;
  102.     ULONG col1, col2;
  103.  
  104.     fe1 = (struct FunctionsEntry *)msg->entry1;
  105.     fe2 = (struct FunctionsEntry *)msg->entry2;
  106.     col1 = msg->sort_type & MUIV_NList_TitleMark_ColMask;
  107.     col2 = msg->sort_type2 & MUIV_NList_TitleMark2_ColMask;
  108.  
  109.     if (msg->sort_type == MUIV_NList_SortType_None) return 0;
  110.  
  111.     if (msg->sort_type & MUIV_NList_TitleMark_TypeMask) {
  112.         cmp = funclist_cmp2colfunc(fe2, fe1, col1);
  113.     } else {
  114.         cmp = funclist_cmp2colfunc(fe1, fe2, col1);
  115.     }
  116.  
  117.     if (cmp != 0 || col1 == col2) return cmp;
  118.  
  119.     if (msg->sort_type2 & MUIV_NList_TitleMark2_TypeMask) {
  120.         cmp = funclist_cmp2colfunc(fe2, fe1, col2);
  121.     } else {
  122.         cmp = funclist_cmp2colfunc(fe1, fe2, col2);
  123.     }
  124.  
  125.     return cmp;
  126. }
  127.  
  128. MakeHook(funclist_cmp2hook, funclist_cmp2func);
  129.  
  130. static ULONG __saveds mNew( struct IClass *cl,
  131.                             Object *obj,
  132.                             struct opSet *msg )
  133. {
  134.     APTR funclist;
  135.  
  136.     if (obj = (Object *)DoSuperNew(cl, obj,
  137.         MUIA_Window_ID, MakeID('.','L','F','T'),
  138.         WindowContents, VGroup,
  139.             Child, funclist = MyNListviewObject(MakeID('F','T','L','V'), "BAR P=" MUIX_R ",BAR P=" MUIX_R ",BAR,BAR", &funclist_con2hook, &funclist_des2hook, &funclist_dsp2hook, &funclist_cmp2hook, FALSE),
  140.         End,
  141.         TAG_MORE, msg->ops_AttrList))
  142.     {
  143.         struct FunctionsWinData *fwd = INST_DATA(cl, obj);
  144.         APTR parent;
  145.  
  146.         fwd->fwd_FunctionsList = funclist;
  147.  
  148.         parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
  149.  
  150.         set(obj, MUIA_Window_ActiveObject, funclist);
  151.  
  152.         DoMethod(parent,   MUIM_Window_AddChildWindow, obj);
  153.         DoMethod(obj,      MUIM_Notify,              MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
  154.         DoMethod(funclist, MUIM_NList_Sort3, MUIV_NList_Sort3_SortType_1, MUIV_NList_SortTypeAdd_None, MUIV_NList_Sort3_SortType_Both);
  155.     }
  156.  
  157.     return (ULONG)obj;
  158. }
  159.  
  160. static ULONG __saveds mDispose( struct IClass *cl,
  161.                                 Object *obj,
  162.                                 struct opSet *msg )
  163. {
  164.     struct FunctionsWinData *fwd = INST_DATA(cl, obj);
  165.  
  166.     set(obj, MUIA_Window_Open, FALSE);
  167.     DoMethod(fwd->fwd_FunctionsList, MUIM_NList_Clear);
  168.  
  169.     return (DoSuperMethodA(cl, obj, msg));
  170. }
  171.  
  172. static ULONG __saveds mShowFunctions( struct IClass *cl,
  173.                                       Object *obj,
  174.                                       Msg msg )
  175. {
  176.     struct FunctionsWinData *fwd = INST_DATA(cl, obj);
  177.     struct MUIP_FunctionsWin_ShowFunctionsMessage *sfm = (struct MUIP_FunctionsWin_ShowFunctionsMessage *)msg;
  178.  
  179.     if (sfm->nodeType != MUIV_FunctionsWin_NodeType_Resource ||
  180.         (stricmp(sfm->name, FSRNAME) != 0 &&
  181.          stricmp(sfm->name, CARDRESNAME) != 0 &&
  182.          stricmp(sfm->name, KEYMAPRESNAME) != 0)) {
  183.  
  184.         struct FunctionsEntry *fe;
  185.  
  186.         if (fe = tbAllocVecPooled(globalPool, sizeof(struct FunctionsEntry))) {
  187.             struct Library *lib = (struct Library *)sfm->base;
  188.             ULONG max, offset;
  189.             BOOL useIdLib = (IdentifyBase != NULL);
  190.  
  191.             max = lib->lib_NegSize;
  192.  
  193.             set(fwd->fwd_FunctionsList, MUIA_NList_Quiet, TRUE);
  194.  
  195.             NoReqOn();
  196.  
  197.             for (offset = LIB_VECTSIZE; offset <= max; offset += LIB_VECTSIZE) {
  198.                 struct JumpEntry *je;
  199.  
  200.                 je = (struct JumpEntry *)((UBYTE *)lib - offset);
  201.                 if (je->je_JMPInstruction == 0x4ef9) {
  202.                     if (points2ram(je->je_JumpAddress)) {
  203.                         _snprintf(fe->fe_Address, sizeof(fe->fe_Address), MUIX_PH "$%08lx" MUIX_PT, je->je_JumpAddress);
  204.                     } else {
  205.                         _snprintf(fe->fe_Address, sizeof(fe->fe_Address), "$%08lx", je->je_JumpAddress);
  206.                     }
  207.                 } else {
  208.                     stccpy(fe->fe_Address, txtNoJump, sizeof(fe->fe_Address));
  209.                 }
  210.  
  211.                 fe->fe_Offset = offset;
  212.                 _snprintf(fe->fe_OffsetDec, sizeof(fe->fe_OffsetDec), "-%ld", offset);
  213.                 _snprintf(fe->fe_OffsetHex, sizeof(fe->fe_OffsetHex), "-$%04lx", offset);
  214.  
  215.                 if ((offset <= LIB_VECTSIZE * 6 && sfm->nodeType == MUIV_FunctionsWin_NodeType_Device) ||
  216.                     (offset <= LIB_VECTSIZE * 4 && sfm->nodeType == MUIV_FunctionsWin_NodeType_Library)) {
  217.                     UBYTE *help;
  218.  
  219.                     switch (offset) {
  220.                         case LIB_VECTSIZE * 1: help = "Open";    break;
  221.                         case LIB_VECTSIZE * 2: help = "Close";   break;
  222.                         case LIB_VECTSIZE * 3: help = "Expunge"; break;
  223.                         case LIB_VECTSIZE * 4: help = "ExtFunc"; break;
  224.                         case LIB_VECTSIZE * 5: help = "BeginIO"; break;
  225.                         case LIB_VECTSIZE * 6: help = "AbortIO"; break;
  226.                         default:               help = ""; break;
  227.                     }
  228.                     stccpy(fe->fe_FuncName, help, sizeof(fe->fe_FuncName));
  229.                 } else if (useIdLib) {
  230.                     ULONG error;
  231.  
  232.                     if (sfm->name) {
  233.                         if (stricmp(sfm->name, CIAANAME) == 0 || stricmp(sfm->name, CIABNAME) == 0) {
  234.                             error = IdFunctionTags("cia.resource", offset, IDTAG_FuncNameStr, fe->fe_FuncName,
  235.                                                                            IDTAG_StrLength, sizeof(fe->fe_FuncName),
  236.                                                                            TAG_DONE);
  237.                         } else {
  238.                             error = IdFunctionTags(sfm->name, offset, IDTAG_FuncNameStr, fe->fe_FuncName,
  239.                                                                       IDTAG_StrLength, sizeof(fe->fe_FuncName),
  240.                                                                       TAG_DONE);
  241.                         }
  242.                         switch (error) {
  243.                             case IDERR_NOFD:
  244.                                 stccpy(fe->fe_FuncName, txtNoFDFile, sizeof(fe->fe_FuncName));
  245.                                 break;
  246.  
  247.                             case IDERR_NOMEM:
  248.                                 fe->fe_FuncName[0] = 0x00;
  249.                                 useIdLib = FALSE;
  250.                                 break;
  251.  
  252.                             case IDERR_OFFSET:
  253.                                 stccpy(fe->fe_FuncName, txtNoFunctionEntry, sizeof(fe->fe_FuncName));
  254.                                 break;
  255.                         }
  256.                     } else {
  257.                         stccpy(fe->fe_FuncName, txtNoFDFile, sizeof(fe->fe_FuncName));
  258.                     }
  259.                 } else {
  260.                     fe->fe_FuncName[0] = 0x00;
  261.                 }
  262.  
  263.                 InsertBottomEntry(fwd->fwd_FunctionsList, fe);
  264.             }
  265.  
  266.             NoReqOff();
  267.  
  268.             set(fwd->fwd_FunctionsList, MUIA_NList_Quiet, FALSE);
  269.  
  270.             set(obj, MUIA_Window_Title, MyGetChildWindowTitle("FUNCTIONS", sfm->name, fwd->fwd_Title, sizeof(fwd->fwd_Title)));
  271.         }
  272.  
  273.         tbFreeVecPooled(globalPool, fe);
  274.     }
  275.  
  276.     set(obj, MUIA_Window_Open, TRUE);
  277.  
  278.     return 0;
  279. }
  280.  
  281. ULONG __asm __saveds FunctionsWinDispatcher( register __a0 struct IClass *cl,
  282.                                              register __a2 Object *obj,
  283.                                              register __a1 Msg msg )
  284. {
  285.     switch (msg->MethodID) {
  286.         case OM_NEW:                          return (mNew(cl, obj, (APTR)msg));
  287.         case OM_DISPOSE:                      return (mDispose(cl, obj, (APTR)msg));
  288.         case MUIM_FunctionsWin_ShowFunctions: return (mShowFunctions(cl, obj, (APTR)msg));
  289.     }
  290.  
  291.     return (DoSuperMethodA(cl, obj, msg));
  292. }
  293.  
  294.